﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="jlparing3_vastus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Jlparing3Vastus))]
    public class Jlparing3VastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IJlparing3Vastus clazz;
        
        public Jlparing3VastusSerializer(IJlparing3Vastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("juhid");
            if (clazz.Juhid!=null) {
                global::Xtee.Core.SerializationMetadata metaJuhid = this.GetMetaData(clazz.Juhid);
                Writer.WriteTypeAttribute(metaJuhid.TypeQualifiedName.Namespace, metaJuhid.TypeQualifiedName.Name);
                metaJuhid.NewSerializer(clazz.Juhid).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Juhid");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "juhid")) {
                goto juhid;
            }
            else {
                return;
            }
        juhid:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>jlparing3_vastus>juhid");
            }
            global::Xtee.Core.SerializationMetadata metaJuhid = this.GetMetaData<Jlparing3Vastus.IJuhidType>(Reader, ">>jlparing3_vastus>juhid", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
            clazz.Juhid = metaJuhid.NewEntity<Jlparing3Vastus.IJuhidType>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("juhid");
                metaJuhid.NewSerializer(clazz.Juhid).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>jlparing3_vastus>juhid", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Jlparing3Vastus.JuhidType))]
        public class JuhidTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Jlparing3Vastus.IJuhidType clazz;
            
            public JuhidTypeSerializer(Jlparing3Vastus.IJuhidType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                for (int x = 0; ((clazz.Item != null) 
                            && (x < clazz.Item.Count)); x = (x + 1)) {
                    if (clazz.Item[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaItem = this.GetMetaData(clazz.Item[x]);
                        Writer.WriteTypeAttribute(metaItem.TypeQualifiedName.Namespace, metaItem.TypeQualifiedName.Name);
                        metaItem.NewSerializer(clazz.Item[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="item") {
                    clazz.Item = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IJuhid3>();
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>jlparing3_vastus>juhid>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaItem = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IJuhid3>(Reader, "juhid3", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                        global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IJuhid3 item = metaItem.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IJuhid3>();
                        clazz.Item.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaItem.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                }
            }
        }
    }
}
